package com.jarvis.order.web;

import cn.hutool.core.util.StrUtil;
import com.jarvis.common.utils.R;
import com.jarvis.order.feign.UserFeignService;
import com.jarvis.order.vo.ApplePayVo;
import com.jarvis.order.vo.ProductVo;
import com.jarvis.order.feign.ProductFeignService;
import com.jarvis.order.vo.UserVo;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class OrderPayController {

    @Autowired
    private ProductFeignService productFeignService;

    @Autowired
    private UserFeignService userFeignService;

    @RequestMapping("/applePay")
    public R doIosRequest(@RequestParam("productId") long productId, @RequestHeader Map<String, String> headers){


        //查询用户
        String uid = headers.get("uid");
        if (StrUtil.isBlank(uid)) {
            return R.error(500,"服务器异常");
        }

       // UserVo userVo  = userFeignService.getUser(Long.parseLong(uid));

        //获取要购买的商品
        ProductVo productVo = productFeignService.getProductEntity(productId);

        //增加用户会员时间
        R result = userFeignService.addVipDay(Long.parseLong(uid),productVo.getVipDay());

        if(result.getCode() == 0) {
          return R.ok();
        }else {
            return R.error(10099,"充值失败");
        }


    }




}
